<%@ page import="java.net.*" %>
<%@ page import="java.io.*" %>
<%@ page import="java.util.*" %>
<%@ page import="pub.digur.util.*" %>

<%
request.setCharacterEncoding("UTF-8");
response.setCharacterEncoding("UTF-8");

String name = (String) session.getAttribute("name");
String password = (String) session.getAttribute("password");
String content = request.getParameter("content");
String urlStr = "http://api.minicloud.com.cn/statuses/update.xml?name=" + name;

System.out.println(urlStr);
System.out.println("content -> " + content);

URL url = new URL(urlStr);
URLConnection conn = url.openConnection();

conn.setRequestProperty("Authorization", "Basic " + Encoder.base64Encode(name + ":" + password));

conn.setDoOutput(true);
PrintWriter pw = new PrintWriter(conn.getOutputStream());
pw.print("content");
pw.print('=');
pw.print(URLEncoder.encode(content, "UTF-8"));

pw.close();

// the result
InputStream in = null;
try
{
	in = conn.getInputStream();
}
catch (Exception e)
{
	e.printStackTrace();
}

Scanner scanner = new Scanner(in);
StringBuilder result = new StringBuilder();
while (scanner.hasNextLine())
{
	result.append(scanner.nextLine());
	result.append("\n");
}

in.close();
System.out.println(result);

// pageContext.forward("digur.user.jsp");
response.sendRedirect("digur.user.jsp");
%>